# -*- coding: utf-8 -*-
# @Time    : 2024/12/1 下午6:04
# @Author  : wjx
# @Email   : kanxinxin@163.com
# @File    : collect_page.py
# @Software: PyCharm
from appium.webdriver.common.appiumby import AppiumBy as By
from pages.base_page import BasePage


class CollectPage(BasePage):
    # 定位器
    # 所有菜谱
    all_cookbooks_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().className('
                                                     '"androidx.appcompat.app.ActionBar$Tab").instance(0)')
    # 菜单
    menu_nav_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().className('
                                                '"androidx.appcompat.app.ActionBar$Tab").instance(1)')
    # 添加菜单
    add_menu_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                '"com.xiachufang:id/img_container").instance(1)')
    # 标题
    title_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/et_title")')
    # 描述
    description_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/et_describe")')
    # 创建
    create_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/tv_right")')
    # 选择第一个菜谱
    select_cookbook_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                       '"com.xiachufang:id/iv_check_box").instance(0)')
    # 完成
    finish_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/tv_right")')

    # 已收藏信息
    collected_inform_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                        '"com.xiachufang:id/common_item_container")')
    # 取消收藏
    dismiss_collect_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                       '"com.xiachufang:id/recipe_bto_nav_bar_collect")')
    # 确认取消收藏
    sure_dismiss_collect_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/tv_right")')
    # 选择第一道菜谱
    choose_first_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                    '"com.xiachufang:id/one_img").instance(0)')
    # 编辑菜谱
    edit_cookbook_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/iv_edit")')
    # 选择菜谱
    choose_menu_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/iv_check_box")')
    # 删除
    delete_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/tv_delete")')
    # 确认删除
    sure_delete_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/tv_right")')

    # 添加菜谱
    add_cookbook_locator = (By.XPATH,'//android.widget.ImageButton[@content-desc="创建"]')

    # 选择第一个菜谱
    select_first_cookbook_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                             '"com.xiachufang:id/iv_check_box").instance(0)')

    # 断言，菜单中是否有内容
    menu_content_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/load_status_layout")')

    # 搜索收藏的菜谱——点击搜索输入框
    search_key_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/search_edit_text")')
    # 搜索按钮
    search_btn_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("搜索")')


    def click_all_cookbooks(self):
        self.find_element(self.all_cookbooks_locator).click()

    def click_menu_nav(self):
        self.find_element(self.menu_nav_locator).click()

    def click_add_menu(self):
        self.find_element(self.add_menu_locator).click()

    def input_title(self, title):
        self.find_element(self.title_locator).send_keys(title)

    def input_description(self, description):
        self.find_element(self.description_locator).send_keys(description)

    def click_create(self):
        self.find_element(self.create_locator).click()

    def click_select_cookbook(self):
        self.find_element(self.select_cookbook_locator).click()

    def click_finish(self):
        self.find_element(self.finish_locator).click()

    def click_collected_inform(self):
        self.find_element(self.collected_inform_locator).click()

    def click_dismiss_collect(self):
        self.find_element(self.dismiss_collect_locator).click()

    def click_sure_dismiss_collect(self):
        self.find_element(self.sure_dismiss_collect_locator).click()

    def click_choose_first(self):
        self.find_element(self.choose_first_locator).click()

    def click_edit_cookbook(self):
        self.find_element(self.edit_cookbook_locator).click()

    def click_choose_menu(self):
        self.find_element(self.choose_menu_locator).click()

    def click_delete(self):
        self.find_element(self.delete_locator).click()

    def click_sure_delete(self):
        self.find_element(self.sure_delete_locator).click()

    def click_add_cookbook(self):
        self.find_element(self.add_cookbook_locator).click()

    def click_select_first_cookbook(self):
        self.find_element(self.select_first_cookbook_locator).click()

    def get_menu_content(self):
        """
        获取菜单中内容
        :return: 菜单中内容
        """
        return self.find_element(self.menu_content_locator).text

    def input_search_key(self,search_key):
        """
        输入搜索关键字
        :param search_key:
        :return: None
        """
        search_key_element = self.find_element(self.search_key_locator)
        search_key_element.click()
        search_key_element.send_keys(search_key)

    def click_search_btn(self):
        """
        点击搜索按钮
        :return: None
        """
        self.find_element(self.search_btn_locator).click()
